using Godot;

public static class Rule
{
    public const int BOARD_WIDTH = 8;
    public const int BOARD_HEIGHT = 9;
    public const int BOARD_SIDE_LEN = 4;
    public const int BOARD_COL = 9;
    public const int BOARD_ROW = 10;

    public static readonly Vector2I[] DIRECTLY_MOVEMENT = [Vector2I.Left, Vector2I.Up, Vector2I.Right, Vector2I.Down];
    public static readonly Vector2I[] DIAGONAL_MOVEMENT = [new(1, 1), new(-1, 1), new(-1, -1), new(1, -1)];

    public static bool AtSide(Side side, int y) => side switch
    {
        Side.Up => y >= 0 && y <= 4,
        Side.Down => y >= 5 && y <= BOARD_HEIGHT,
        _ => false,
    };

    public static Side GetTeamSide(int team) => team == 1 ? Side.Up : Side.Down;

    public static bool InBoardCol(int x) => x >= 0 && x <= BOARD_WIDTH;
    public static bool InBoardRow(int y) => y >= 0 && y <= BOARD_HEIGHT;
    public static bool OnBoard(int x, int y) => InBoardCol(x) && InBoardRow(y);
    public static bool OnBoard(Vector2I p) => OnBoard(p.X, p.Y);

    public static bool InHeadquarter(Side side, int x, int y) => x >= 3 && x <= 5 && y >= (side == Side.Up ? 0 : 7) && y <= (side == Side.Up ? 2 : 9);

    public static int ColOppsite(int col) => BOARD_WIDTH - col;

    public static Side Oppsite(this Side side) => side switch
    {
        Side.Up => Side.Down,
        Side.Down => Side.Up,
        _ => Side.Up,
    };
}